Skip to content

Conversation

@wikaaaaa
Copy link
Contributor

@wikaaaaa wikaaaaa commented Feb 9, 2026

Description

This PR adds gen_ai.tool_definitions to completion hook and configures exporting the attribute to GCS. Its configured the same way as system instructions, it's being hashed, since it might be large and often doesn't differ.

Its a continuation of #4142, which added gen_ai.tool_definitions to gen_ai.client.inference.operation.details.

Please delete options that are not relevant.

New feature (non-breaking change which adds functionality)

How Has This Been Tested?

  • Manual tests: run adk web and inspected the traces and data send to the storage bucket
  • Unit tests

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

return [asdict(dc) for dc in dataclass_list]
response: JsonEncodeable = []
for data in data_list:
if isinstance(data, dict):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In what case will it be a dict ? Don't you always serialize the tool definitions to a sting ? And otherwise it's a dataclass ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tool definitions are serialized into dictionaries, and in a fallback to a string.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DylanRussell ping on this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it makes sense for it to be this way, I confused myself thinking the hashed tool definitions (which I think is always a string) would be passed to this..

But this function takes the tool definitions as they are on the attribute, and in that case it'll be a dict or fallback to a string: https://github.com/open-telemetry/opentelemetry-python-contrib/blob/main/instrumentation-genai/opentelemetry-instrumentation-google-genai/src/opentelemetry/instrumentation/google_genai/generate_content.py#L237



def is_tool_definitions_hashable(
tool_definitions: list[types.MessagePart] | None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is tool definitions of types.MessagePart and can you give an example of what you would pass here?

I think we should have a dedicated type for this that callers have to convert to before calling this API. The other types in this API are part of the semantic conventions

"""Represents a tool call requested by the model
This model is specified as part of semconv in `GenAI messages Python models - ToolCallRequestPart
<https://github.com/open-telemetry/semantic-conventions/blob/main/docs/gen-ai/non-normative/models.ipynb>`__.
"""

Could we align with open-telemetry/semantic-conventions#3378?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants